package LC23;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author zhangsan
 */
public class LC2215 {
    public static List<List<Integer>> findDifference(int[] nums1, int[] nums2) {
        int[] arr1 = Arrays.stream(nums1).sorted().distinct().toArray();
        int[] arr2 = Arrays.stream(nums2).sorted().distinct().toArray();
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        int l1 = arr1.length;
        int l2 = arr2.length;
        int a = 0, b = 0;
        while (a < l1 && b < l2) {
            if (arr1[a] == arr2[b]) {
                a++;
                b++;
            } else if (arr1[a] < arr2[b]) {
                list1.add(arr1[a]);
                a++;
            } else {
                list2.add(arr2[b]);
                b++;
            }
            if (a == l1) {
                for (int i = b; i < l2; i++) {
                    list2.add(arr2[i]);
                }
            } else if (b == l2) {
                for (int i = a; i < l1; i++) {
                    list1.add(arr1[i]);
                }
            }
        }
        return Arrays.asList(list1, list2);
    }

    public static void main(String[] args) {
        List<List<Integer>> difference = findDifference(new int[]{1, 2, 3, 3}, new int[]{1, 1,2, 2});
        System.out.println(difference);
    }
}
